namespace _13 {

var romanToInt = function(s: string): number {
    let map: { [index: string]: number } = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 }
    let subtractiveNotation: { [index: string]: number } = { 'IV': 4, 'IX': 9, 'L': 50, 'XL': 40, 'XC': 90, 'CD': 400, 'CM': 900 }
    let answer = 0
    for(var i = 0; i < s.length; i++) {
        let x = s.substr(i, 2)
        if (x.length > 1 && subtractiveNotation[x] !== undefined) {
            answer += subtractiveNotation[x]
            i++
        }
        else {
            answer += map[s[i]]
        }
    }
    return answer;
};    

//console.assert( romanToInt(''))

}